package com.atu.atugra.service.impl;
 
import com.atu.atugra.constant.AppHttpCodeEnum;
import com.atu.atugra.tools.CommonResult;
import com.atu.atugra.tools.JwtUtil;
import com.atu.atugra.tools.VoidJudgeUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atu.atugra.mapper.AdminsMapper;
import com.atu.atugra.entity.Admins;
import com.atu.atugra.service.AdminsService;
import org.springframework.stereotype.Service;

/**
 * (Admins)表服务实现类
 *
 * @author makejava
 * @since 2025-02-07 12:01:18
 */
@Service("adminsService")
public class AdminsServiceImpl extends ServiceImpl<AdminsMapper, Admins> implements AdminsService {
    //登录结构
    @Override
    public CommonResult login(Admins admin) {
        LambdaQueryWrapper<Admins> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Admins::getUsername, admin.getUsername());
        queryWrapper.eq(Admins::getPassword, admin.getPassword());
        Admins one = this.getOne(queryWrapper);
        if(VoidJudgeUtils.isBlank(one)){
            return CommonResult.failed(AppHttpCodeEnum.LOGIN_ERROR);
        }
        String token = JwtUtil.createToken(one);
        return CommonResult.okResult(token);
    }
}
